package com.project.mapper;

import com.project.pojo.Admin;
import com.project.pojo.Build;
import com.project.pojo.Notice;
import com.project.pojo.Room;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface AdminMapper {
    /**
     * 管理员更改个人信息
     */
    @Update("update tb_admin set adminId =#{adminId} ,password = #{password} " +
            ",relName = #{relName} ,number = #{number} where id = #{id};")
    void update(Admin admin);

    /**
     * 查询所有管理员
     * @return
     */
    @Select("select * from tb_admin;")
    List<Admin> selectAllAdmin();

    /**
     * 查询管理员信息
     */
    List<Admin> selectByInfo(Admin admin);

    /**
     * 登陆精准验证
     */
    @Select("select * from tb_admin where adminId = #{adminId} and password = #{password};")
    Admin login(@Param("adminId") String adminId, @Param("password") String password);
    
    //==================================================================================================
    
    /**
     * 添加公告
     * @param notice
     */
    @Insert("insert into tb_note (id, note, type) values (null,#{note},#{type});")
    void addNotice(Notice notice);

    /**
     * 添加教学楼
     * @param build
     */
    @Insert("insert into tb_build (buildId, buildName, buildStatus, buildNote) " +
            "values (null,#{buildName},#{buildStatus},#{buildNote});")
    void addBuild(Build build);

    /**
     * 添加教室
     * @param room
     */
    @Insert("insert into tb_room (id, roomId, buildId,status) " +
            "values (null,#{roomId},#{buildId},#{status});")
    void addRoom(Room room);

    /**
     * 删除 公告
     * @param noticeId
     */
    @Delete("delete from tb_note where id = #{noticeId};")
    void deleteNotice(long noticeId);

    /**
     * 更改公告
     * @param notice
     */
    @Update("update tb_note set note = #{note},type = #{type} where id = #{id};")
    void updateNotice(Notice notice);

    /**
     * 更改教学楼信息
     * @param build
     */
    @Update("update tb_build set buildName = #{buildName}," +
            "buildStatus = #{buildStatus},buildNote = #{buildNote} where buildId = #{buildId};")
    void updateBuild(Build build);

    /**
     * 更改教室信息
     * @param room
     */
    @Update("update tb_room set roomId = #{roomId}, status = #{status} where id = #{id};")
    void updateRoom(Room room);

    /**
     * 查询所有公告
     * @return
     */
    @Select("select * from tb_note;")
    List<Notice> selectAllNotice();

    /**
     * 查询所有教学楼
     * @return
     */
    @Select("select * from tb_build;")
    List<Build> selectAllBuild();

    /**
     * 查询所有 教室
     * @return
     */
    @Select("SELECT r.*,b.buildName FROM tb_room r,tb_build b WHERE r.buildId = b.buildId;")
    List<Room> selectAllRoom();

    /**
     * 更改教室状态
     */
    @Update("update tb_room set status = #{status} where roomId = #{roomId} and buildId = #{buildId};")
    void updateRoomStatus(Room room);
}
